/******************************************************************************
 * Copyright (c) 2014 - 2016. Danlu.com Co.Ltd. All rights reserved.          *
 ******************************************************************************/
package cn.com.dhc.danlu.widget.couponview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import cn.com.dhc.danlu.R;

/**
 * @author: 李一方
 * @author: 吴海洋
 * @version: 1.0.0
 * @since: 2016-11-07 04:20
 * @mail: liyifang@danlu.com
 * @desc: 优惠券视图
 */
public class DanluYHQView extends BaseDanluCouponView {
    private SawtoothView svLeft;

    public DanluYHQView (Context context) {
        super (context);
    }

    public DanluYHQView (Context context, AttributeSet attrs) {
        super (context, attrs);
    }

    public DanluYHQView (Context context, AttributeSet attrs, int defStyleAttr) {
        super (context, attrs, defStyleAttr);
    }

    @Override
    protected int getViewLayoutId () {
        return R.layout.view_coupon_yhq;
    }

    @Override
    protected void initChildView (View root) {
        svLeft = (SawtoothView) root.findViewById (R.id.sv_left);
    }

    @Override
    protected boolean isYhq () {
        return true;
    }

    @Override
    public void setGetState (CouponGetState state) {
        switch (state) {
            case getOver:
                svLeft.setEnabled (true);
                svRight.setEnabled (false);
                setActionText ("已\n领\n取");
                tvPrice.setEnabled (true);
                tvUnit.setEnabled (true);
                tvQuota.setEnabled (true);
                setRightActionIsVisible (VISIBLE, GONE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_50));
                break;

            case grabOver:
                svLeft.setEnabled (false);
                svRight.setEnabled (false);
                setActionText ("已\n抢\n完");
                tvPrice.setEnabled (false);
                tvUnit.setEnabled (false);
                tvQuota.setEnabled (false);
                setRightActionIsVisible (VISIBLE, GONE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_50));
                break;

            case getNow:
                svLeft.setEnabled (true);
                svRight.setEnabled (true);
                setActionText ("立\n即\n领\n取");
                tvPrice.setEnabled (true);
                tvUnit.setEnabled (true);
                tvQuota.setEnabled (true);
                setRightActionIsVisible (VISIBLE, GONE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_50));
                break;
        }
    }

    @Override
    protected void handleOtherUseSituation (CouponUseState state) {
        switch (state) {
            case dateOver:
                svLeft.setEnabled (false);
                tvPrice.setEnabled (false);
                tvUnit.setEnabled (false);
                setActionText ("已\n过\n期");
                svRight.setEnabled (false);
                setRightActionIsVisible (VISIBLE, GONE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_50));
                break;

            case usedNot:
                svLeft.setEnabled (true);
                tvPrice.setEnabled (true);
                tvUnit.setEnabled (true);
                cftAction.setText ("立\n即\n使\n用");
                svRight.setEnabled (true);
                setRightActionIsVisible (VISIBLE, GONE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_50));
                break;

            case usedOver:
                svLeft.setEnabled (true);
                tvPrice.setEnabled (true);
                tvUnit.setEnabled (true);
                setRightActionIsVisible (GONE, VISIBLE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_30));
                break;
        }
    }

    private void setActionText (String s) {
        cftAction.setText (s);
    }
}
